package com.itheima.dao;

import com.itheima.pojo.Permission;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

public interface PermissionDao {

    @Select("select * from t_permission")
    public List<Permission> getAllPermission();

    @Insert("insert into t_role_permission (role_id,permission_id) values (#{roleId},#{permissionId})")
    public void insertRoleIdAndPermissionId(@Param("roleId") Integer roleId,@Param("permissionId") Integer permissionId);

    @Select("select * from t_permission")
    public Set<Permission> getByRole(Integer roleId);

    // 根据用户名获取所有的权限 id
    @Select("select permission_id from t_role_permission where role_id=#{roleId}")
    public List<Integer> getByRoleId(Integer roleId);

    @Delete("delete from t_role_permission where role_id=#{roleId}")
    public void delectRleIdAndPermission(Integer roleId);

    @Select("select * from t_permission where name like CONCAT('%',#{queryString},'%')")
    List<Permission> getByQueryString(String queryString);

    @Insert("insert into t_permission (name,keyword,description,creationDate,available_or_not) values (#{name},#{keyword},#{description},#{creationDate},#{available_or_not})")
    void insertPermission(Permission permission);

    @Select("select * from t_permission where id=#{permissionId}")
    public Permission findById(Integer permissionId);

    @Update("update t_permission set name=#{name},keyword=#{keyword},description=#{description},available_or_not=#{available_or_not} where id=#{id}")
    void updatePermission(Permission permission);
    @Select("select count(*) from t_role_permission where permission_id=#{permissionId}")
    public Integer getByPermissionId(Integer permissionId);

    @Delete("delete from t_permission where id=#{permissionId}")
    void deletePermission(Integer permissionId);
}
